package phytagorasbaum;

import com.dinim.math.GeometryUtil;
import com.dinim.math.TrigonometryUtil;
import com.dinim.matrix.twodimensional.IPoint2D;
import com.dinim.object.Line2D;
import com.dinim.object.Rectangle2D;

public class PythagorasBaumData {

    public Rectangle2D root;
    public double x;
    public double y;
    
    public PythagorasBaumData(int x, int y, int width, int height) {
        root = new Rectangle2D(x, y, width, height);
    }
    
    public IPoint2D getUpperLeft(){
        return root.getPoints()[0];
    }
    
    public IPoint2D getUpperRight(){
        return root.getPoints()[1];
    }
    
    public IPoint2D getLowerLeft(){
        return root.getPoints()[3];
    }
    
    public IPoint2D getLowerRight(){
        return root.getPoints()[2];
    }
    
    public static void main(String[] args) {
        PythagorasBaumData pbd = new PythagorasBaumData(0, 0, 100, 100);
        System.out.println(pbd.getBottomAngle());
        System.out.println(pbd.getTopAngle());
        IPoint2D[] p = pbd.root.getPoints();
        Line2D line = new Line2D(p[0], p[1]);
        line.rotate(-10, line.getCenterPoint());
        pbd.root.rotate(-9, pbd.root.getCenterPoint());
        System.out.println(pbd.getBottomAngle());
        System.out.println(pbd.getTopAngle());
    }
    
    public double getBottomAngle(){
        IPoint2D[] p = root.getPoints();
        IPoint2D p2 = p[2];
        IPoint2D p3 = p[3];
        double H = getBottomLength();
        double A = GeometryUtil.getLength(p3.getX(), p3.getY(), p2.getX(), p3.getY());
        return TrigonometryUtil.getAngleWithAdjacentLeg(A, H);
    }
    
    public double getTopAngle(){
        IPoint2D[] p = root.getPoints();
        IPoint2D p2 = p[0];
        IPoint2D p3 = p[1];
        double H = getTopLength();
        double A = GeometryUtil.getLength(p3.getX(), p3.getY(), p2.getX(), p3.getY());
        return TrigonometryUtil.getAngleWithAdjacentLeg(A, H);
    }
    
    public double getBottomLength(){
        IPoint2D[] p = root.getPoints();
        IPoint2D p2 = p[2];
        IPoint2D p3 = p[3];
        return GeometryUtil.getLength(p2.getX(), p2.getY(), p3.getX(), p3.getY());
    }
    
    public double getTopLength(){
        IPoint2D[] p = root.getPoints();
        IPoint2D p2 = p[0];
        IPoint2D p3 = p[1];
        return GeometryUtil.getLength(p2.getX(), p2.getY(), p3.getX(), p3.getY());
    }
    
    public double getAlphaLength(){
        IPoint2D[] p = root.getPoints();
        return GeometryUtil.getLength(p[0].getX(), p[0].getY(), x, y);
    }
    
    public double getBetaLength(){
        IPoint2D[] p = root.getPoints();
        return GeometryUtil.getLength(x, y, p[1].getX(), p[1].getY());
    }
    
    public double getAlpha(){
        IPoint2D[] p = root.getPoints();
        double H = getTopLength();
        double A = getAlphaLength();
        return TrigonometryUtil.getAngleWithAdjacentLeg(A, H);
    }

    public double getBeta(){
        IPoint2D[] p = root.getPoints();
        double H = getTopLength();
        double A = getBetaLength();
        return TrigonometryUtil.getAngleWithAdjacentLeg(A, H);
    }
    
    public double getTopToBottomRatio(){
        return getTopLength() / getBottomLength();
    }
    
    public double getAlphaRatio(){
        return getAlphaLength() / getTopLength();
    }
    
    public double getBetaRatio(){
        return getBetaLength() / getTopLength();
    }
    
    
    
}
